﻿/// <reference path="vswd-ext_2.2.js" />


function showLocationWindow(){
    var latiDegree = new Ext.form.NumberField({
		fieldLabel:_LocationSearch_Latitude,
		maxValue:90,
		maxText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		labelSeparator:"",
		labelStyle:"padding-left:6px",
		width:50
    });
    
    var longiDegree = new Ext.form.NumberField({
		fieldLabel:_LocationSearch_Longitude,
		maxValue:180,
		maxText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		labelSeparator:"",
		labelStyle:"padding-left:6px",
		width:50
    });
    
    var latiMinute = new Ext.form.NumberField({
	    hideLabel:true,
	    maxValue:60,
		maxText:_LocationSearch_DataOver,
		minValue:0,
		minText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
	    width:50
    });
    
    var longiMinute = new Ext.form.NumberField({
        width:50,
        maxValue:60,
		maxText:_LocationSearch_DataOver,
		minValue:0,
		minText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		hideLabel:true
    });
    
    var latiSecond = new Ext.form.NumberField({
		hideLabel:true,
		maxValue:60,
		maxText:_LocationSearch_DataOver,
		minValue:0,
		minText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		width:50
	});
	
	var longiSecond = new Ext.form.NumberField({
		hideLabel:true,
		maxValue:60,
		maxText:_LocationSearch_DataOver,
		minValue:0,
		minText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		width:50
	});
	
	var decimalLati = new Ext.form.NumberField({
		fieldLabel:_LocationSearch_Latitude,
		decimalPrecision:6,
		maxValue:90,
		minValue:-90,
		maxText:_LocationSearch_DataOver,
		minText:_LocationSearch_DataOver,
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		labelStyle:"padding-left:6px",
		labelSeparator:"",
		width:75
	});
	
	var decimalLongi = new Ext.form.NumberField({
		fieldLabel:_LocationSearch_Longitude,
		decimalPrecision:6,
		maxValue:180,
		maxText:_LocationSearch_DataOver,
		minValue:-180,
		minText:_LocationSearch_DataOver,
		labelStyle:"padding-left:6px",
		allowBlank:false,
        blankText:_NewForText_CanNotEmpty,
		labelSeparator:"",
		width:75
	});
	
	var cmbNSSearchLocation = new Ext.form.ComboBox({
        hideLabel:true,
        editable:false,
        store: northsouthstore ,
        valueField:'valueid',
        displayField:'val',
        typeAhead: false,
        mode: 'local',
        forceSelection: true ,
        triggerAction: 'all',
        emptyText:'',
        selectOnFocus:true,
        width:40
    });
	
	var cmbEWSearchLocation = new Ext.form.ComboBox({
        hideLabel:true,
        editable:false,
        store: eastweststore,
        valueField:'valueid',
        displayField:'val',
        typeAhead: false,
        mode: 'local',
        forceSelection: true ,
        triggerAction: 'all',
        emptyText:'',
        selectOnFocus:true,
        width:40
    });
    
	cmbEWSearchLocation.setValue('E');
    cmbNSSearchLocation.setValue('N');

    var locationwin = new Ext.Window({
        title: _LocationSearch_Title,
        width: 500,
        height: 200,
        layout: "form",
        items: [
			{
			    xtype: "panel",
			    title: _LocationSearch_SearchByType1 + " (" + _LocationSearch_Help1 + ")",
			    layout: "table",
			    height: 90,
			    header: true,
			    width: "",
			    items: [
					{
					    xtype: "panel",
					    title: "panrow1column1",
					    style: "padding-top:5px",
					    labelWidth: 90,
					    width: 160,
					    height: 80,
					    header: false,
					    layout: "form",
					    border: false,
					    items: [
							latiDegree,
							longiDegree
						]
					},
					{
					    xtype: "panel",
					    title: "panrow1column2",
					    style: "padding-top:5px",
					    height: 80,
					    width: 60,
					    header: false,
					    border: false,
					    layout: "form",
					    items: [
							latiMinute,
							longiMinute
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    border: false,
					    height: 80,
					    width: 60,
					    header: false,
					    layout: "form",
					    items: [
							latiSecond, longiSecond
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    border: false,
					    layout: "form",
					    header: false,
					    height: 80,
					    width: 70,
					    items: [
						    cmbNSSearchLocation,
						    cmbEWSearchLocation
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    header: false,
					    border: false,
					    height: 80,
					    width: 60,
					    layout: 'absolute',
					    items: [
							{
							    xtype: "button",
							    text: _LocationSearch_Go,
							    y: 30,
							    handler: function() {
							        if (imap != null) {
							            if (latiDegree.isValid() && latiMinute.isValid() && latiSecond.isValid() && longiDegree.isValid()
								            && longiMinute.isValid() && longiSecond.isValid()) {
							                var lats = parseFloat(latiSecond.getValue());
							                var latm = parseFloat(latiMinute.getValue());
							                var lat = parseFloat(latiDegree.getValue()) + fn60To100(latm + fn60To100(lats));
							                var lngs = parseFloat(longiSecond.getValue());
							                var lngm = parseFloat(longiMinute.getValue());
							                var lng = parseFloat(longiDegree.getValue()) + fn60To100(lngm + fn60To100(lngs));
							                if (cmbNSSearchLocation.getValue() == "S")
							                    lat = -lat;
							                if (cmbEWSearchLocation.getValue() == "W")
							                    lng = -lng;

							                
							                imap.findLocation(lat,lng, _LocationSearch_Latitude, _LocationSearch_Longitude);
							            }
							        }
							    }
							}
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    layout: "form",
					    width: 60,
					    header: false,
					    border: false,
					    height: 80,
					    layout: 'absolute',
					    items: [
							{
							    xtype: "button",
							    text: _LocationSearch_Clear,
							    style: "padding-top:30px",
							    y: 30,
							    handler: function() {
							        latiDegree.reset();
							        latiMinute.reset();
							        latiSecond.reset();
							        longiDegree.reset();
							        longiMinute.reset();
							        longiSecond.reset();
							        if (imap != null)
							            imap.removeFound();
							    }
							}
						]
					}
				]
			},
			{
			    xtype: "panel",
			    title: _LocationSearch_SearchByType2 + " (" + _LocationSearch_Help2 + ")",
			    headerAsText: true,
			    height: 60,
			    header: true,
			    layout: "table",
			    items: [
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    layout: "form",
					    autoHeight: false,
					    height: 40,
					    labelWidth: 70,
					    header: false,
					    border: false,
					    width: 175,
					    cls: "",
					    items: [
							decimalLati
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    width: 175,
					    height: 40,
					    header: false,
					    border: false,
					    layout: "form",
					    labelWidth: 70,
					    items: [
							decimalLongi
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    header: false,
					    border: false,
					    height: 40,
					    width: 60,
					    layout: "form",
					    items: [
							{
							    xtype: "button",
							    text: _LocationSearch_Go,
							    handler: function() {
							        if (imap != null) {
							            if (decimalLati.isValid() && decimalLongi.isValid()) {
							                var lati = parseFloat(decimalLati.getValue());
							                var longi = parseFloat(decimalLongi.getValue());
							                
							                imap.findLocation(lati,longi, _LocationSearch_Latitude, _LocationSearch_Longitude);
							            }
							        }
							    }
							}
						]
					},
					{
					    xtype: "panel",
					    title: "My Panel",
					    style: "padding-top:5px",
					    width: 60,
					    height: 40,
					    header: false,
					    border: false,
					    items: [
							{
							    xtype: "button",
							    text: _LocationSearch_Clear,
							    handler: function() {
							        decimalLati.reset();
							        decimalLongi.reset();
							        if (imap != null)
							            imap.removeFound();
							    }
							}
						]
					}
				]
			}
		]
    })
    
    locationwin.show();
    
    
}

function fn60To100(v){
    return v/60;
}